import {createBrowserRouter } from "react-router-dom";
import Home from "@/views/Home";
import Login from "@/views/Login";
import Layout from "@/views/Layout";
import AuthRoute from "./modules/AuthRoute";
import { Suspense } from "react";
import store from "@/store";


function generateRoutesFromMenuList(menuList: any[]) {
    return menuList.map((menu) => ({
      path: menu.path,
      element: <div>{menu.name}</div>,
    }));
  }
console.log(store.getState().user.menuList , "user.menuList");

//   const menuList = useSelector((state:any) => state.user.menuList);

//   const dynamicRoutes = generateRoutesFromMenuList(menuList);


const router = createBrowserRouter([
	{
		path: "/",
		element: (
			<AuthRoute>
				<Layout />
			</AuthRoute>
		),
		children: [
			{
				index: true,
				element: (
					<Suspense fallback={"加载中"}>
						<Home />
					</Suspense>
				),
			},
            // ...dynamicRoutes
		],
	},
	{
		path: "/login",
		element: <Login />,
	},
]);

export default router;
